package com.example.javatwo.service.cg.wmj;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.javatwo.mapper.cg.wmj.buyReturnMapping;
import com.example.javatwo.pojo.cg.wmj.PurchaseReturn;
import com.example.javatwo.pojo.cg.wmj.PurchaseReturnInfo;

@Service
public class buyReturnService {
	@Autowired
	private buyReturnMapping buyreturn;
	//主祥查询
	public List<PurchaseReturn> QueryBuy(int currentPage){
		List<PurchaseReturn> buy = buyreturn.QueryBuy(currentPage);
		for (PurchaseReturn purchaseReturn : buy) {
			List<PurchaseReturnInfo> info = buyreturn.QueryBuyInfo(purchaseReturn.getBillNo());
			purchaseReturn.setInfo(info);
		}
		return buy;
	}
	
	public int QuerySumCount(){
		return this.buyreturn.QuerySumCount();
	}
	
	//主祥新增
	public void InsertPurchaseReturn(PurchaseReturn purchase){
		int i = buyreturn.QueryCount(purchase.getBillNo());
		if(i>0){
			buyreturn.DeletePurchaseReturn(purchase.getBillNo());
		}
		buyreturn.InsertPurchaseReturn(purchase);
	}
	
	//查询 审核状态
	public String QueryStatus(String billNo){
		String state = buyreturn.QueryStatus(billNo);
		return state;
	}
		
	//查询最大单号  by 单据日期
//	public String QueryBillNo(String date){
//		String billNo = this.buyreturn.QueryBillNo(date);
//		if(billNo!=null || billNo!=""){
//			billNo =String.valueOf(Long.parseLong(billNo)+1);
//		}else{
//			billNo = date.replace("-","").toString()+"01";
//		}
//		return billNo;
//	}
	public String QueryBillNo(String date){
		String billNo = this.buyreturn.QueryBillNo(date);
		//billNo =String.valueOf(Long.parseLong(billNo)+1);
		if(billNo!=null ||!("").equals(billNo)){
			billNo=String.valueOf(Long.parseLong(billNo+1));
		}else{
			billNo=date.replace("-","").toString()+"01";
		}
		return billNo;
		
	}
	
	
	public void UpdateSupplier(@Param("money")Double money,@Param("id")String id){
		buyreturn.UpdateSupplier(money, id);
	}
	
	public void UpdateProduct(@Param("num")int num,@Param("money")Double money,@Param("id")String id){
		buyreturn.UpdateProduct(num, money, id);
	}
	
	
	
}
